
<%@page import="org.lxy.domain.UserInfoEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="cn.hutool.system.UserInfo" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>用户管理</title>
<base href="<%=basePath%>" />
<link rel="Stylesheet" type="text/css" href="/css/Form.css" />
<link href="../../style/css.css" rel="stylesheet" type="text/css" />
<link rel="Stylesheet" type="text/css"
	href="css/themes/base/jquery.ui.all.css" />
<script type="text/javascript" src="/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(function() {
		var role = $("#txtRole").val();

		if (role == "3") {
			$("#btnAdd").hide();
		}
		if (role == "2") {
			$("#btnAdd").hide();
			$("#btnEdit").hide();

		}
	});
	function Add() {
		var url = "/userinfo/operation?op=Add";
		$("#EditFrame").attr("src", "/userinfo/operation?op=Add");
		$("#EditDialog").dialog({
			bgiframe : true,
			height : 450,
			width : 300,
			modal : true
		});
		$("#EditDialog").dialog('open');
	}
	function Update() {
		var icount = getCount();
		if (icount == 0) {
			alert('请选择一条数据进行修改！');
			return;
		}
		if (icount > 1) {
			alert('只能同时修改一条数据！');
			return;
		}
		$("#EditFrame")
				.attr(
						"src",
						"/userinfo/operation?op=Edit&id="
								+ $(
										"input[type = 'checkbox'][name = 'checkuser']:checked")
										.val() + "&update=1");
		$("#EditDialog").dialog({
			bgiframe : true,
			height : 450,
			width : 300,
			modal : true
		});
		$("#EditDialog").dialog("open");
	}
	function Delete() {
		var icount = getCount();
		if (icount == 0) {
			alert("请选择要删除的数据！");
			return false;
		} else {
			if (confirm("确定要删除当前选择的 " + icount + " 条数据吗？")) {
				//执行删除的操作
				var ids = "";
				$("input[type='checkbox'][name='checkuser']:checked").each(
						function() {
							ids += $(this).val() + ",";
						});
				$.post("/userinfo/delete", {
					ids : ids
				}, function(data) {
					if (data == "1") {
						alert("删除成功！");

					} else {
						alert("删除失败！");
					}
					window.location.reload();
				});
			} else {
				return;
			}
		}
	}

	function getCount() {
		return $("input[type='checkbox'][name='checkuser']:checked").length;
	}
	function closedialog() {
		$("#EditDialog").dialog('close');
	}
</script>
</head>
<body>
	<form id="form1" runat="server">
		<input type="hidden" id="txtRole"
			value="<%=request.getParameter("role")%>" />
		<div class="position">当前位置 > userinfo</div>
		<div>
			<div class="line"></div>
			<div class="search">
				<input type="button" id="btnAdd" value="添加" onclick="Add();"
					class="btn_css  submitbg" />&nbsp; <input type="button"
					id="btnEdit" value="编辑" onclick="Update();"
					class="btn_css  submitbg" />&nbsp; <input type="button" value="删除"
					onclick="Delete()" class="btn_css  submitbg" />
			</div>
			<table id="gvUser" class="table_list" cellpadding="0">
				<tr>
					<th>选择</th>
					<th>用户名</th>
					<th>密码</th>
					<th>电话</th>
				</tr>
				<%
					if (request.getAttribute("list") != null) {
						ArrayList<UserInfoEntity> userinfolist = (ArrayList<UserInfoEntity>) request.getAttribute("list");
						for (UserInfoEntity userinfo : userinfolist) {
				%>
				<tr>
					<td><input type="checkbox" name="checkuser"
						value=<%=userinfo.getId()%> /></td>
					<td><%=userinfo.getUsername()%></td>
					<td><%=userinfo.getPassword()%></td>
					<td><%=userinfo.getTelephone()%></td>
				</tr>
				<%
					}
					}
				%>
			</table>
		</div>
		<div id="EditDialog" title="编辑" style="display: none;">
			<iframe id="EditFrame" frameborder="0" width="100%" height="100%"></iframe>
		</div>
	</form>
</body>
</html>
